package com.nablasystems.suag.service;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nablasystems.suag.domain.Usuario;

@Service("usuarioService")
@Transactional
public class UsuarioService {
	
	protected static Logger logger=Logger.getLogger("service");
	
	/*@Resource(name="sessionFactory")*/
	@Autowired
	private SessionFactory sessionFactory;

	@SuppressWarnings("unchecked")
	public Usuario validarUsuario(String legajo, String pass){
		Session session=sessionFactory.getCurrentSession();
		
		Query query=session.createQuery("FROM Usuario u where u.usuario = :usuario and u.password = :pass");
		query.setParameter("usuario", legajo);
		query.setParameter("pass", pass);
		
		List<Usuario> listaUsuarios=query.list();
		if(listaUsuarios.size()>0){
			return listaUsuarios.get(0);
		}
		else{
			return null;
		}
	}
}
